/*
 * Copyright 2015 Zhongan.com All right reserved. This software is the
 * confidential and proprietary information of Zhongan.com ("Confidential
 * Information"). You shall not disclose such Confidential Information and shall
 * use it only in accordance with the terms of the license agreement you entered
 * into with Zhongan.com.
 */
package com.zhongan.gateway.web.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhongan.gateway.bean.Developer;
import com.zhongan.gateway.bean.DeveloperIp;
import com.zhongan.gateway.common.exception.GatewayException;
import com.zhongan.gateway.service.DeveloperService;
import com.zhongan.gateway.web.common.BaseController;
import com.zhongan.gateway.web.common.PageDTO;
import com.zhongan.gateway.web.common.ResultBase;

/***
 * 测试用的Controller
 * 
 * @author
 */
@Controller
@RestController
@Configuration
@RequestMapping("/dev")
public class DeveloperController extends BaseController {

    //    private Logger logger = LoggerFactory.getLogger(TestController.class);

    @Resource
    private DeveloperService developerService;

    @RequestMapping("/deleteDeveloperById")
    ResultBase<Object> deleteDeveloperById(Long id, String appKey) {
        if (id == null) {

        }
        int i = developerService.deleteDeveloperById(id, appKey);
        return getSucResultBase(i);
    }

    @RequestMapping("/insertDeveloper")
    ResultBase<Object> insertDeveloper(Developer developer) {
        int i = 0;
        if (null != developer.getId() && 0 != developer.getId()) {
            i = developerService.updateDeveloper(developer);
            return getSucResultBase(i);
        } else {

            String appkey = developerService.insertDeveloper(developer);
            return getSucResultBase(appkey);
        }

    }

    @RequestMapping("/updateDeveloper")
    ResultBase<Object> updateDeveloper(Developer developer) {

        int i = developerService.updateDeveloper(developer);
        return getSucResultBase(i);
    }

    @RequestMapping("/getDeveloperById")
    ResultBase<Object> getDeveloperById(Long id) {

        Developer de = developerService.selectDeveloperById(id);
        return getSucResultBase(de);
    }

    @RequestMapping("/getDevelopers")
    PageDTO<Developer> getDevelopers(String appKey, String devName, Integer start, Integer limit)
            throws GatewayException {

        PageDTO<Developer> list = developerService.selectPageDevelopers(appKey, devName, start, limit);
        return list;
    }

    @RequestMapping("/deleteIpById")
    ResultBase<Object> deleteIpById(DeveloperIp developerIp) {

        int i = developerService.deleteIpById(developerIp.getId(), developerIp.getDeveloperId());
        return getSucResultBase(i);
    }

    @RequestMapping("/insertIp")
    ResultBase<Object> insertIp(DeveloperIp developerIp) {

        int i = developerService.insertIp(developerIp);
        return getSucResultBase(i);
    }

    @RequestMapping("/getIpById")
    ResultBase<Object> getIpById(Long id) {

        DeveloperIp developerIp = developerService.selectIpById(id);
        return getSucResultBase(developerIp);
    }

    @RequestMapping("/getIps")
    ResultBase<Object> getIps(Long developerId) {
        List<DeveloperIp> list = developerService.selectIps(developerId);
        return getSucResultBase(list);
    }

}
